﻿using SPFluid.Core.Validation.Utilities;

namespace SPFluid.Core.Validation.Extensions
{
    public static class IntegerValidationExtensions
    {
        public static IGuard<int> IsOdd(this IGuard<int> guard)
        {
            if (!MathUtility.IsOdd(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentOutOfRangeException();
            }

            return guard;
        }

        public static IGuard<long> IsOdd(this IGuard<long> guard)
        {
            if (!MathUtility.IsOdd(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentOutOfRangeException();
            }

            return guard;
        }

        public static IGuard<int> IsEven(this IGuard<int> guard)
        {
            if (!MathUtility.IsEven(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentOutOfRangeException();
            }

            return guard;
        }

        public static IGuard<long> IsEven(this IGuard<long> guard)
        {
            if (!MathUtility.IsEven(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentOutOfRangeException();
            }

            return guard;
        }

        public static IGuard<int> IsPrime(this IGuard<int> guard)
        {
            if (!MathUtility.IsPrime(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentException("Not a prime number");
            }

            return guard;
        }

        public static IGuard<long> IsPrime(this IGuard<long> guard)
        {
            if (!MathUtility.IsPrime(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentException("Not a prime number");
            }

            return guard;
        } 
    }
}